package com.fjec.common.aliyun.api;

import com.alibaba.cloudapi.sdk.constant.SdkConstant;
import com.alibaba.cloudapi.sdk.enums.HttpMethod;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;
import com.fjec.common.aliyun.api.view.BusinessLicenseVO;
import com.fjec.common.util.FileUtil;
import com.fjec.common.util.JsonUtil;

import java.util.HashMap;
import java.util.Map;

public class BusinessLicenseClient extends BaseAliyunApi {

    private final static String HOST = "dm-58.data.aliyun.com";

    private final static String PATH = "/rest/160601/ocr/ocr_business_license.json";

    public BusinessLicenseClient(HttpClientBuilderParams params){
        super(params);
    }

    @Override
    public String getHost() {
        return HOST;
    }

    @Override
    public String getPath() {
        return PATH;
    }

    @Override
    public HttpMethod getHttpMethod() {
        return HttpMethod.POST_BODY;
    }

    public static void main(String[] args) throws Exception {
        HttpClientBuilderParams param = new HttpClientBuilderParams();
        param.setAppKey(BaseAliyunApi.TEST_ACCESS_KEY_ID);
        param.setAppSecret(BaseAliyunApi.TEST_SECRET);
        BusinessLicenseClient client = new BusinessLicenseClient(param);
        String str64 = FileUtil.getFileBase64("d:\\license_1.jpg");
        Map<String, Object> body = new HashMap<>();
        body.put("image", str64);
        String jsonStr = JsonUtil.toJson(body);
        ApiResponse response = client.syncReq(jsonStr.getBytes(SdkConstant.CLOUDAPI_ENCODING));
        String resultStr = new String(response.getBody() , SdkConstant.CLOUDAPI_ENCODING);
        Map<String, Object> map = JsonUtil.jsonToMap(resultStr);
        BusinessLicenseVO vo = BusinessLicenseVO.build(map);
        System.out.println("isSuccess=" + vo.isSuccess());
        System.out.println("getRegNum=" + vo.getRegNum());
        System.out.println("getName=" + vo.getName());
        System.out.println("getBusiness=" + vo.getBusiness());
        System.out.println("getType=" + vo.getType());
        System.out.println("getPerson=" + vo.getPerson());
        System.out.println("getAddress=" + vo.getAddress());
        System.out.println("getCapital=" + vo.getCapital());
        System.out.println("getEstablishDate=" + vo.getEstablishDate());
        System.out.println("getValidPeriod=" + vo.getValidPeriod());
        System.out.println("isFake=" + vo.isFake());
    }
}